package com.ghn.cocknovel.ext

import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.ghn.cocknovel.R
import com.kt.NetworkModel.App
import com.kt.NetworkModel.bean.BqueryBean
import com.kt.NetworkModel.bean.ResultListBean
import com.scwang.smartrefresh.layout.SmartRefreshLayout


/**
 */
/**
 * @param mSize 每页展示的数量，不满足则不会加载更多
 */
fun <T> pageLoad(mSmartRefreshLayout: SmartRefreshLayout, it: ResultListBean<T>, mAdapter: BaseQuickAdapter<T, BaseViewHolder>, mSize: Int = 20) {
    //判断当前数据是否为空
    if (it.totalPage == 0) {
        mAdapter.setNewData(emptyList())
        mAdapter.emptyView = View.inflate(App.get(), R.layout.empty_content, null)
        mSmartRefreshLayout.apply {
            finishRefresh()
            setEnableLoadMore(false)
        }
        return
    }

    //是否能加载更多
    mSmartRefreshLayout.setEnableLoadMore(it.pageSize == mSize)
    if (it.isRefresh()) {
        mAdapter.setNewData(it.list)
        mSmartRefreshLayout.finishRefresh()
    } else {
        mSmartRefreshLayout.finishLoadMore()
        mAdapter.addData(it.list)
    }

}

fun <T> pageLoadBase(mSmartRefreshLayout: SmartRefreshLayout, it: ResultListBean<T>, mAdapter: BaseQuickAdapter<T, BaseViewHolder>, mSize: Int = 20) {
    //判断当前数据是否为空
    if (it.totalPage == 0) {
        mAdapter.setNewData(emptyList())
        mAdapter.emptyView = View.inflate(App.get(), R.layout.empty_content, null)
        mSmartRefreshLayout.apply {
            finishRefresh()
        }
        return
    }
    if (it.isRefresh()) {
        mAdapter.setNewData(it.list)
        mSmartRefreshLayout.finishRefresh()
    } else {
        mAdapter.addData(it.list)
    }
    //是否能加载更多
    if (it.list.size == mSize) {
        mAdapter.loadMoreComplete()
    } else {
        mAdapter.loadMoreEnd()
    }
}

fun <T> pageLoadBase(it: ResultListBean<T>, mAdapter: BaseQuickAdapter<T, BaseViewHolder>, mSize: Int = 20) {
    //判断当前数据是否为空
    if (it.totalPage == 0) {
        mAdapter.setNewData(emptyList())
        mAdapter.emptyView = View.inflate(App.get(), R.layout.empty_content, null)
        return
    }
    if (it.isRefresh()) {
        mAdapter.setNewData(it.list)
    } else {
        mAdapter.addData(it.list)
        if (it.list.size == mSize) {
            mAdapter.loadMoreComplete()
        } else {
            mAdapter.loadMoreEnd()
        }
    }
    //是否能加载更多
    if (it.list.size == mSize) {
        mAdapter.loadMoreComplete()
    } else {
        mAdapter.loadMoreEnd()
    }

}
fun <T> MappageLoadBase(it: BqueryBean<T>, mAdapter: BaseQuickAdapter<T, BaseViewHolder>, mSize: Int = 20,) {
    //判断当前数据是否为空
    if (it.totalPage == 0) {
        mAdapter.setNewData(emptyList())
        mAdapter.emptyView = View.inflate(App.get(), R.layout.empty_content, null)
        return
    }
    if (it.isRefresh()) {
        mAdapter.setNewData(it.list)
    } else {
        mAdapter.addData(it.list)
        if (it.list.size == mSize) {
            mAdapter.loadMoreComplete()
        } else {
            mAdapter.loadMoreEnd()
        }
    }
    //是否能加载更多
    if (it.list.size == mSize) {
        mAdapter.loadMoreComplete()
    } else {
        mAdapter.loadMoreEnd()
    }

}